/**
 * 
 */
package fy.hr.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Hashtable;
import java.util.Map;

import fy.config.FyConfig;
import fy.util.DBUtil;


/**
 * @author Administrator
 * 
 */
public class InitManager {

	private static final Map<String, Map<String, String>> leaveTypeMap = new Hashtable<String, Map<String, String>>();

	public static String getLeaveTypeID(String corp, String leaveTypeName) {
		Map<String, String> typeMap = leaveTypeMap.get(corp);
		if (typeMap != null) {
			return typeMap.get(leaveTypeName);
		}
		return null;
	}

	public static void initLeaveTypeMap() {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			conn = fy.util.DBUtil.connect(FyConfig.getEHR_DB_CONFIG());

			pst = conn
					.prepareStatement("select t.pk_timeitem,t.timeitemname, t.pk_corp from tbm_timeitem t where t.fathertimeitem  = 'leaveclass'");

			rs = pst.executeQuery();

			if (rs.next()) {
				setLeaveTypeMap(rs.getString(3), rs.getString(2),
						rs.getString(1));
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, pst, conn);
		}
	}

	private static void setLeaveTypeMap(String corp, String name, String id) {
		Map<String, String> typeMap = leaveTypeMap.get(corp);
		if (typeMap != null) {
			typeMap = new Hashtable<String, String>();
		}
		typeMap.put(name, id);
	}
}
